@extends('Backstage.Layouts.layout')

@section('content')


    <div class="layui-btn-group demoTable">
        <a href="{{URL::route('admin_user_save')}}" class="layui-btn ">创建账号</a>
    </div>

    <hr class="layui-bg-green">
    <div class="table layui-form layui-form-pane">
        搜索账号：
        <div class="layui-inline">
            <input class="layui-input"  id="admin_user_account" autocomplete="off">
        </div>
        搜索名称：
        <div class="layui-inline">
            <input class="layui-input"  id="admin_user_name" autocomplete="off">
        </div>
        搜索电话：
        <div class="layui-inline">
            <input class="layui-input"  id="admin_user_phone" autocomplete="off">
        </div>
        角色：
        <div class="layui-input-inline">
            <select id="admin_user_role"  lay-verify="required" lay-vertype="tips" >
                @foreach(\App\Http\Models\Backstage\AdminRole::queryRoleSelectList(true) as $key=>$val)
                    <option value="{{$key}}">{{$val}}</option>
                @endforeach
            </select>
        </div>
       <br><br>
        状态：
        <div class="layui-input-inline">
            <select id="admin_user_status"  lay-verify="required" lay-vertype="tips" >
                @foreach(\App\Http\Models\Backstage\AdminUser::getStatusName('status','arr',1) as $key=>$val)
                    <option value="{{$key}}">{{$val}}</option>
                @endforeach
            </select>
        </div>
        <button class="layui-btn" data-type="reload">搜索</button>
    </div>

    <table id="list" lay-filter="list"></table>
    <script type="text/html" id="bar">
        {{--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>--}}
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script type="text/html" id="status">
        <input type="checkbox" name="admin_user_status" data-id="@{{d.admin_user_id}}" value="@{{d.admin_user_status}}" title="启用" lay-filter="status" @{{ d.admin_user_status == 1 ? 'checked' : '' }}>
    </script>
    <script type="text/html" id="img">
        <img alt="image" class="img-circle" style="width: 24px;height: 24px;" src="@{{d.admin_user_headimg}}">
    </script>
@stop
@section('script')
    <script>


        layui.use('table', function(){
            var table = layui.table,form = layui.form;

            //监听锁定操作
            form.on('checkbox(status)', function(obj){
                setStatus(obj,'{{URL::route('admin_user_status')}}',this.name);
            });
            layer.msg('数据渲染中···', {
                icon: 16
                ,shade: 0.01
            },0);
            //第一个实例
            table.render({
                elem: '#list'
                ,method: 'post'
                ,where:{_token:'{{csrf_token()}}'}
                ,limit:10
                ,loading:true
                ,cellMinWidth: 120
                ,url: '{{URL::route('admin_user_index')}}' //数据接口
                ,page: true //开启分页
                ,cols: [[ //表头
                    {field: 'admin_user_account', title: '后台账号' ,fixed: 'left'}
                    ,{field: 'admin_user_name', title: '真实姓名'}
                    ,{field: 'admin_user_headimg', title: '头像',width:80,toolbar: '#img'}
                    ,{field: 'admin_role_name', title: '角色'}
                    ,{field: 'admin_user_phone', title: '手机'}
                    ,{field: 'admin_user_mail', title: '邮箱'}
                    ,{field: 'admin_user_status', title: '状态', sort: true,templet: '#status', unresize: true}
                    ,{field: 'admin_user_created_time', title: '创建时间'}
                    ,{field: 'menu',title: '操作', fixed: 'right',toolbar: '#bar'}

                ]],done:function () {
                    layer.closeAll();
                }
            });

            //监听工具条
            table.on('tool(list)', function(obj){
                var data = obj.data;

                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
//                        obj.del();
                        del(data.admin_user_id,'{{URL::route('admin_user_del')}}');
                    });
                } else if(obj.event === 'edit'){
                    location.replace('{{URL::route('admin_user_save')}}'+'?id='+data.admin_user_id);
                }
            });

            var active = {
                reload: function(){
                    layer.msg('数据渲染中···', {
                        icon: 16
                        ,shade: 0.01
                    },0);
                    //执行重载
                    table.reload('list', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        ,where: {
                            param: {
                                admin_user_account: $('#admin_user_account').val(),
                                admin_user_name:$('#admin_user_name').val(),
                                admin_user_phone:$('#admin_user_phone').val(),
                                admin_user_status:$('#admin_user_status').val(),
                                admin_user_role:$('#admin_user_role').val()
                            }
                        }
                    });
                }
            };

            $('.table .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

        });
    </script>
@stop

